//
//  DMTabBarController.m
//  DistributionMallApp
//
//  Created by JHnoplan on 2018/10/18.
//  Copyright © 2018年 JHnoplan. All rights reserved.
//

#import "DMTabBarController.h"
#import "DMHomeVC.h"
#import "DMNewsVC.h"
#import "DMMineVC.h"

@interface DMTabBarController ()

@end

@implementation DMTabBarController

//适配iphoneX tabbar
-(void)viewWillLayoutSubviews {
    [super viewWillLayoutSubviews];
    if (self.tabBar.frame.size.height == 83) {
        CGRect tabFrame = self.tabBar.frame;
        tabFrame.origin.y = ScreenHeight-82;
        tabFrame.size.height = 82;
        self.tabBar.frame = tabFrame;
        self.tabBar.barStyle = UIBarStyleDefault;
    }
}

+(void)load
{
    // 获取当前类下所有的tabBarItem
    UITabBarItem *item = [UITabBarItem appearanceWhenContainedIn:self, nil];
    // 设置选中标题的颜色
    // 创建富文本属性字典
    NSMutableDictionary *testAttr = [NSMutableDictionary dictionary];
    // 描述颜色
    testAttr[NSForegroundColorAttributeName] = DMMainColor;
    // 设置标题的富文本属性
    [item setTitleTextAttributes:testAttr forState:UIControlStateSelected];
    // 问题:设置字体颜色不好使,注意:一定要先设置正常状态下字体大小
    // 设置正常状态下字体
    NSMutableDictionary *testAttrNor = [NSMutableDictionary dictionary];
    // 描述字体
    testAttrNor[NSFontAttributeName] = [UIFont systemFontOfSize:11];
    // 设置标题的富文本属性
    [item setTitleTextAttributes:testAttrNor forState:UIControlStateNormal];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.tabBar.translucent = NO;
//    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    
    [self setupAllChildViewController];
    [self setupAllTabBarButton];
}

-(void)setupAllChildViewController
{
    // 首页
    DMHomeVC *mainVC =[[DMHomeVC alloc]init];
    DMNavigationController *nav0=[[DMNavigationController alloc]initWithRootViewController:mainVC];
    nav0.navigationItem.title = @"商城";
    nav0.navigationBar.translucent = NO;
    [nav0.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont boldSystemFontOfSize:18]}];
    [self addChildViewController:nav0];
    
    // 分类
    DMNewsVC *orderCVC=[[DMNewsVC alloc]init];
    DMNavigationController *nav1=[[DMNavigationController alloc]initWithRootViewController:orderCVC];
    nav1.navigationItem.title = @"消息";
    nav1.navigationBar.translucent = NO;
    [nav1.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont boldSystemFontOfSize:18]}];
    [self addChildViewController:nav1];
    
    // 购物车
    DMMineVC *individualVC=[[DMMineVC alloc]init];
    DMNavigationController *nav2=[[DMNavigationController alloc]initWithRootViewController:individualVC];
    nav2.navigationBar.translucent = NO;
    nav2.navigationItem.title = @"我的";
    [nav2.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont boldSystemFontOfSize:18]}];
    [self addChildViewController:nav2];
    
    // 我的
    //    BZMineVC *personalVC=[[BZMineVC alloc]init];
    //    BZNavigationController *nav3=[[BZNavigationController alloc]initWithRootViewController:personalVC];
    //    nav3.navigationItem.title = @"My Account";
    //    nav3.navigationBar.translucent = NO;
    //    [self addChildViewController:nav3];
}

-(void)setupAllTabBarButton{
    DMNavigationController *nav0=self.childViewControllers[0];
    nav0.tabBarItem.title=@"商城";
    nav0.tabBarItem.image=[UIImage imageWithRenderingOriginalName:@"foot_home_wxz"];
    nav0.tabBarItem.selectedImage=[UIImage imageWithRenderingOriginalName:@"foot_home_xz"];
    
    DMNavigationController *nav1=self.childViewControllers[1];
    nav1.tabBarItem.title=@"消息";
    nav1.tabBarItem.image=[UIImage imageWithRenderingOriginalName:@"foot_xiaoxi_wsz"];
    nav1.tabBarItem.selectedImage=[UIImage imageWithRenderingOriginalName:@"foot_xiaoxi_xz"];
    
    DMNavigationController *nav2=self.childViewControllers[2];
    nav2.tabBarItem.title=@"我的";
    nav2.tabBarItem.image=[UIImage imageWithRenderingOriginalName:@"foot_me_wsz"];
    nav2.tabBarItem.selectedImage=[UIImage imageWithRenderingOriginalName:@"foot_me_xz"];
    
    //    BZNavigationController *nav3=self.childViewControllers[3];
    //    nav3.tabBarItem.title=@"My Account";
    //    nav3.tabBarItem.image=[UIImage imageNamed:@"my"];
    //    nav3.tabBarItem.selectedImage=[UIImage imageWithRenderingOriginalName:@"my1"];
}

@end
